package com.ftwj.demo.utils.result;

import java.io.Serializable;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

@ApiModel(value="API通用返回接口",description="",discriminator="WangshengLi")
public class ResultBean<T> implements Serializable {

	private static final long serialVersionUID = 1L;
	/**
     * 	通用返回状态
     */
	@ApiModelProperty(value = "通用返回状态码", required = true)
	private Integer code;
	 /**
     * 	通用返回信息
     */
	@ApiModelProperty(value = "通用返回消息", required = true)
	private String message;
	/**
     * 	通用返回数据
     */
	@ApiModelProperty(value = "通用返回数据", required = true)
	private T data;
	
	public Integer getCode() {
		return code;
	}

	public String getMessage() {
		return message;
	}

	public T getData() {
		return data;
	}

	public ResultBean() {
		super();
	}

	private ResultBean(MessageEnum message) {
	    this.code = message.getCode();
	    this.message = message.getMessage();
	}
	
	private ResultBean(MessageEnum message, T data) {
		this.code = message.getCode();
		this.message = message.getMessage();
		this.data = data;
	}
	
	private ResultBean(Integer code, String message) {
        this.code = code;
        this.message = message;
    }
	
	public ResultBean(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

	public static <T> ResultBean<T> success() {
		return new ResultBean<T>(MessageEnum.SERVER_SUCCESS);
	}
	
	public static <T> ResultBean<T> success(T data) {
        return new ResultBean<T>(MessageEnum.SERVER_SUCCESS, data);
    }
	
	public static <T> ResultBean<T> error(MessageEnum massage) {
		return new ResultBean<T>(massage,null);
	}
	
	public static <T> ResultBean<T> error(MessageEnum massage,String str) {
		return new ResultBean<T>(massage.getCode(),String.format(massage.getMessage(), str));
	}
	
	public static <T> ResultBean<T> error(Integer code, String massage) {
        return new ResultBean<T>(code,massage);
    }

    @Override
    public String toString() {
        return "ResultBean [code=" + code + ", message=" + message + ", data=" + data + "]";
    }
    
}
